package 第5章多线程编程作业.Work1.Work5;

public class Ticket implements Runnable {

    private  int tickets = 100;
    private  int count = 1;
    static boolean flag = false;

    public void run() {
        synchronized (new Ticket()) {
            if (count< 100) {
                for (int i = count; i < 101; i++) {
                    if (Thread.currentThread().getName() == "小黄牛" && flag == false) {
                        System.out.println(Thread.currentThread().getName() + "抢到第" + count + "张票");
                        flag = true;
                        count++;
                        tickets--;

                    }
                    if (Thread.currentThread().getName() == "小黄牛" && flag == true) {
                        break;
                    }

                    System.out.println(Thread.currentThread().getName() + "抢到第" + count + "张票");
                    count++;
                    tickets--;


                }
            }
        }
    }
}